package algo;

import divTools.Converter;
import objects.AccessPoint;
import objects.ReferencePoint;

public class Friis {

	/**
	 * Computes the friis index between an access point and a reference point
	 * @param ap
	 * @param refPoint
	 * @return
	 */
	public static Float computeFriisIndex(AccessPoint ap, ReferencePoint refPoint) {
		
		float power;
		
		if (refPoint.getMeasurements().containsKey(ap.getMacAdress())) {
			power = refPoint.getMeasurements().get(ap.getMacAdress()).getPowerValue();
		}
		else {
			return null;
		}
		
		float gr = Converter.dBmToMw(5);
		float gt = Converter.dBmToMw(ap.getAntennaGain());
		
		float pt = Converter.dBmToMw(ap.getOutputPower());
		float pr = Converter.dBmToMw(power);
		
		float y = (float) (300000000 / (ap.getFrequency() * 4 * Math.PI));
		float d = Distance.computeDistance(ap.getCoordinates(), refPoint.getCoordinates());
	
		return (float)((10 * Math.log10(gt * gr) 
				+ 10 * Math.log10(pt) 
				+ 20 * Math.log10(y) 
				- 10 * Math.log10(pr))
				/ (10 * Math.log10(d)));
	}
}